  # -*- coding: UTF-8 -*-   
  #Twisted MMORPG   
from twisted.internet.protocol import Factory   
from twisted.protocols.basic import LineOnlyReceiver   
from twisted.internet import reactor   
import random   
import string   

class Game(LineOnlyReceiver):       
 def lineReceived(self, data):     
	 print data
	 self.transport.write(data) 
 def getId(self):           
	 return str(self.transport.getPeer())   
 def connectionMade(self):           
	 print "New User Login:", self.getId()     
	 self.transport.write("欢迎来到MMO世界！\n")           
	 self.factory.addClient(self)       
 def connectionLost(self, reason):  
	 print reason        
	 self.factory.delClient(self)   
            
class GameFactory(Factory):       
     protocol = Game       
     def __init__(self):           
         self.clients = []   
         self.player = []   
         self.msg=''    
         self.x = range(100,700)   
         self.y = range(100,500)      
     def getPlayerId(self):   
         return len(self.player)   
     def addClient(self, newclient):      
            self.clients.append(newclient)    
     def delClient(self, client):           
         self.clients.remove(client)       
     def sendAll(self, data):   
         print data   

 #      self.transport.write('<cross-domain-policy><allow-access-from domain="127.0.0.1" to-ports="*"/></cross-domain-policy>\0')   
                
reactor.listenTCP(8006, GameFactory())   
reactor.run()